package com.zds.zhouyi.ui;


import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zds.zhouyi.R;
import com.zds.zhouyi.model.Gua;
import com.zds.zhouyi.util.ResUtil;
import com.zds.zhouyi.util.StringUtil;

import java.util.List;

public class QuickGuaAdapter extends BaseQuickAdapter<Gua, BaseViewHolder> {

    public QuickGuaAdapter(List<Gua> data) {
        super(R.layout.gua_item, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Gua gua) {
        baseViewHolder.setText(R.id.tv_gua_info, ResUtil.getString(R.string.gua_no, StringUtil.numberToChinese(gua.getId())) + " " + gua.getName() + ": " + gua.getDescrip());

        ImageView gua1 = baseViewHolder.findView(R.id.iv_gua1);
        ImageView gua2 = baseViewHolder.findView(R.id.iv_gua2);
        ImageView gua3 = baseViewHolder.findView(R.id.iv_gua3);
        ImageView gua4 = baseViewHolder.findView(R.id.iv_gua4);
        ImageView gua5 = baseViewHolder.findView(R.id.iv_gua5);
        ImageView gua6 = baseViewHolder.findView(R.id.iv_gua6);
        int[] guaArray = new int[6];
        for (int i = 0; i < gua.getCode().length(); i++) {
            guaArray[i] = gua.getCode().charAt(i) - '0';
        }
        gua1.setBackgroundResource(guaArray[0] == 1 ? R.color.black : R.drawable.yin);
        gua2.setBackgroundResource(guaArray[1] == 1 ? R.color.black : R.drawable.yin);
        gua3.setBackgroundResource(guaArray[2] == 1 ? R.color.black : R.drawable.yin);
        gua4.setBackgroundResource(guaArray[3] == 1 ? R.color.black : R.drawable.yin);
        gua5.setBackgroundResource(guaArray[4] == 1 ? R.color.black : R.drawable.yin);
        gua6.setBackgroundResource(guaArray[5] == 1 ? R.color.black : R.drawable.yin);
    }

}